package me.leon.ext.java

import org.junit.Assert
import org.junit.Test

class HexTest {

    @Test
    fun hex2binaryTest() {
        val hex = "4c656f6e"

        //        HexUtils.hexStringToBytes(d)?.also { println(it.contentToString()) }
        //            ?.map { it.toChar().toString() }.also { print(it) }
        val expected = byteArrayOf(76, 101, 111, 110)
        val r: ByteArray? = HexUtils.hexStringToBytes(hex)
        r?.also { println(it.contentToString()) }?.map { it.toChar().toString() }.also { print(it) }

        Assert.assertArrayEquals(expected, r)
    }

    @Test
    fun binary2HexTest() {
        val expected = "4c656f6e"
        val byteArray = byteArrayOf(76, 101, 111, 110)
        val r = HexUtils.bytesToHexString(byteArray).also { print(it) }
        Assert.assertEquals(expected, r)
    }
}
